package com.qen.yanggao

import cn.hutool.db.Db
import cn.hutool.poi.excel.ExcelUtil

fun main() {
    val inTbale = ArrayList<String>()
    for (str in tableList) {
        inTbale.add("'${str}'")
    }
    val list = Db.use().query("select * from SCHEMATA where SCHEMA_NAME in (${inTbale.joinToString(",")})")
    val rows = ArrayList<Schema>()
    for (entity in list) {
        rows.add(Schema(
            name = entity.getStr("schema_name"),
            code = entity.getStr("default_character_set_name")
        ))
    }
    outExcel(rows)
}

data class Schema(
    val name: String = "",
    val code: String = ""
)

fun outExcel(rows: ArrayList<Schema>) {
    val writer = ExcelUtil.getWriter("${OutPath}4数据表登记导入模板Sheet2.xlsx")
    writer.addHeaderAlias("name", "数据库名称")
    writer.addHeaderAlias("code", "数据库编码")

    writer.write(rows, true)
    writer.close()
}